Skip to content

fix: add nil check for os.Stdout to prevent panic on Windows services#275

Merged
fatih merged 3 commits intofatih:mainfrom
majiayu000:fix-250-need-a-method-to-avoid-the-pan-0101-1659
Mar 20, 2026
Merged

fix: add nil check for os.Stdout to prevent panic on Windows services#275
fatih merged 3 commits intofatih:mainfrom
majiayu000:fix-250-need-a-method-to-avoid-the-pan-0101-1659

Conversation

@majiayu000
Copy link
Copy Markdown
Contributor

Fixes #250

Changes

  • Add nil check in stdoutIsTerminal() before calling os.Stdout.Fd()
  • Add initOutput() to safely initialize Output with nil check for os.Stdout
  • Add initError() to safely initialize Error with nil check for os.Stderr
  • Add nil check in color_windows.go init() before accessing os.Stdout.Fd()

Signed-off-by: majiayu000 <1835304752@qq.com>
fatih pushed a commit that referenced this pull request Feb 1, 2026
Comprehensive analysis of open issues and PRs with prioritization:
- Critical: Windows service panic fix (PR #275), new release needed
- High: VS Code color detection issues, NO_COLOR runtime behavior
- Medium: tabwriter compatibility docs, hyperlink support, performance opt
- Maintenance: 4 dependabot PRs pending

https://claude.ai/code/session_01YJ5Uw2RTABLo4Cx4Jmzmua
fatih added 2 commits March 20, 2026 11:19
Problem:

The nil-safe writer helpers in this PR are named  and , which reads like package init work instead of standard stream accessors. The related docs also still describe the old defaults.

Solution:

Rename the helpers to  and , and update the nearby doc comments so  and  describe the actual default writers.
@fatih
Copy link
Copy Markdown
Owner

fatih commented Mar 20, 2026

@majiayu000 thank you for your fix. I pushed an additional test and renamed some of the functions. Going to merge it as it.

@fatih fatih merged commit 05e1c8c into fatih:main Mar 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need a method to avoid the panic when os.Stdout is nil on windows platform.

2 participants